<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>static_export (Table::RBook)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File rbook.rb, line 40</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">static_export</span> <span class="ruby-identifier">borders</span>=<span class="ruby-keyword kw">true</span>,<span class="ruby-identifier">old_html</span>=<span class="ruby-keyword kw">nil</span>
      <span class="ruby-comment cmt">#     iterate over tables</span>
      <span class="ruby-identifier">sheets</span> = <span class="ruby-value str">&quot;Sheets: &quot;</span>
      <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword kw">in</span> <span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">length</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>
        <span class="ruby-identifier">sheets</span> = <span class="ruby-identifier">sheets</span> <span class="ruby-operator">+</span> <span class="ruby-node">&quot;&lt;a href=#{@bname}#{i}.html&gt;#{i}&lt;/a&gt; &quot;</span>
      <span class="ruby-keyword kw">end</span>
      <span class="ruby-ivar">@tables</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">tbl</span>,<span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">table</span>=<span class="ruby-identifier">tbl</span>.<span class="ruby-identifier">clone</span>
        <span class="ruby-identifier">table</span>.<span class="ruby-identifier">rows</span> = <span class="ruby-identifier">tbl</span>.<span class="ruby-identifier">clone</span>.<span class="ruby-identifier">rows</span>.<span class="ruby-identifier">clone</span>
        <span class="ruby-identifier">b</span>=<span class="ruby-value str">&quot;&quot;</span>
        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">borders</span>
          <span class="ruby-identifier">b</span> = <span class="ruby-value str">&quot;border=1&quot;</span> <span class="ruby-comment cmt"># draw table borders and td borders</span>
        <span class="ruby-keyword kw">end</span>
        <span class="ruby-identifier">html</span> = <span class="ruby-node">&quot;&lt;html&gt;&lt;body&gt;#{sheets}&lt;br&gt;&lt;table #{b}&gt;\n&quot;</span>
        <span class="ruby-comment cmt"># the out file</span>
        <span class="ruby-identifier">hfile</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@fpath</span>,<span class="ruby-ivar">@bname</span><span class="ruby-operator">+</span><span class="ruby-node">&quot;#{i}.html&quot;</span>),<span class="ruby-value str">'w'</span>)
        <span class="ruby-identifier">hfile</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">html</span>
        <span class="ruby-identifier">hfile</span>.<span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;&lt;tr&gt;&lt;td&gt;#&lt;/td&gt;&quot;</span>
        <span class="ruby-comment cmt"># column numbers </span>
        <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword kw">in</span> <span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">table</span>.<span class="ruby-identifier">length</span>[<span class="ruby-value">1</span>]
          <span class="ruby-identifier">hfile</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;&lt;td&gt;#{i}&lt;/td&gt;&quot;</span>
        <span class="ruby-keyword kw">end</span>
        <span class="ruby-identifier">hfile</span>.<span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;&lt;/tr&gt;&quot;</span>
        <span class="ruby-identifier">table</span>.<span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each_with_index</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">ro</span>,<span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
          <span class="ruby-identifier">row</span> = <span class="ruby-identifier">ro</span>.<span class="ruby-identifier">clone</span>
          <span class="ruby-identifier">hfile</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;&lt;tr&gt;&lt;td&gt;#{r}&lt;/td&gt;&quot;</span> <span class="ruby-comment cmt"># row numbers</span>
          <span class="ruby-comment cmt"># add cells to row if needed (draws a pretty table)</span>
          <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">:cols</span>].<span class="ruby-identifier">length</span><span class="ruby-operator">-</span><span class="ruby-value">1</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">table</span>.<span class="ruby-identifier">length</span>[<span class="ruby-value">1</span>]
              <span class="ruby-identifier">table</span>.<span class="ruby-identifier">rows</span>[<span class="ruby-identifier">r</span>][<span class="ruby-identifier">:cols</span>] = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">rows</span>[<span class="ruby-identifier">r</span>][<span class="ruby-identifier">:cols</span>].<span class="ruby-identifier">clone</span>
            <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword kw">in</span> <span class="ruby-value">0</span><span class="ruby-operator">..</span>(<span class="ruby-identifier">table</span>.<span class="ruby-identifier">length</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">row</span>[<span class="ruby-identifier">:cols</span>].<span class="ruby-identifier">length</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>)<span class="ruby-operator">+</span><span class="ruby-value">1</span>
              <span class="ruby-identifier">row</span>[<span class="ruby-identifier">:cols</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;&amp;nbsp;&quot;</span>
            <span class="ruby-keyword kw">end</span>
          <span class="ruby-keyword kw">end</span>
          <span class="ruby-comment cmt"># iterate cells in row</span>
          <span class="ruby-identifier">row</span>[<span class="ruby-identifier">:cols</span>].<span class="ruby-identifier">each_with_index</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">col</span>,<span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
            <span class="ruby-comment cmt"># 1m bold 3m italic 4m underline 9m strik</span>
            <span class="ruby-identifier">tags</span> = <span class="ruby-node">%w[&lt;b&gt; &lt;i&gt; &lt;u&gt; &lt;del&gt;]</span>
            <span class="ruby-identifier">tend</span> = <span class="ruby-node">%w[&lt;/b&gt; &lt;/i&gt; &lt;/u&gt; &lt;/del&gt;]</span>
            <span class="ruby-identifier">ansi</span> = <span class="ruby-identifier">abs_format</span>(<span class="ruby-identifier">table</span>,<span class="ruby-identifier">r</span>,<span class="ruby-identifier">c</span>) <span class="ruby-comment cmt">#ansi seq string</span>
            <span class="ruby-identifier">ansi</span> = <span class="ruby-value str">&quot;&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">ansi</span>
            <span class="ruby-comment cmt"># colors</span>
            <span class="ruby-identifier">bg</span> = <span class="ruby-identifier">ansi</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/\[4[0-9]m/</span>)[<span class="ruby-value">0</span>]
            <span class="ruby-identifier">fg</span> = <span class="ruby-identifier">ansi</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/\[3[0-9]m/</span>)[<span class="ruby-value">0</span>]
            <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fg</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/([0-9]+)/</span>
              <span class="ruby-identifier">fg</span> = <span class="ruby-identifier">$1</span>
            <span class="ruby-keyword kw">else</span>
              <span class="ruby-identifier">fg</span> = <span class="ruby-keyword kw">nil</span>
            <span class="ruby-keyword kw">end</span>
            <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">bg</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/([0-9]+)/</span>
              <span class="ruby-identifier">bg</span>=<span class="ruby-identifier">$1</span>
            <span class="ruby-keyword kw">else</span>
              <span class="ruby-identifier">bg</span> = <span class="ruby-keyword kw">nil</span>
            <span class="ruby-keyword kw">end</span>
            <span class="ruby-identifier">fg</span> = <span class="ruby-identifier">get_color_num</span> <span class="ruby-identifier">fg</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fg</span>
            <span class="ruby-identifier">bg</span> = <span class="ruby-identifier">get_color_num</span> <span class="ruby-identifier">bg</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">bg</span>
            <span class="ruby-identifier">bg</span> = <span class="ruby-value str">&quot;&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">bg</span>;<span class="ruby-identifier">fg</span>=<span class="ruby-value str">&quot;&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">fg</span>
            <span class="ruby-comment cmt"># underloine bold italic strike</span>
            <span class="ruby-identifier">font</span>=[];<span class="ruby-identifier">fontend</span>=[]
            <span class="ruby-node">%w[1m 3m 4m 9m]</span>.<span class="ruby-identifier">each_with_index</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">a</span>,<span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
              <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">ansi</span>.<span class="ruby-identifier">index</span>(<span class="ruby-node">&quot;\e[#{a}&quot;</span>)
                <span class="ruby-identifier">font</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">tags</span>[<span class="ruby-identifier">i</span>];<span class="ruby-identifier">fontend</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">tend</span>[<span class="ruby-identifier">i</span>]
              <span class="ruby-keyword kw">end</span>
            }
            <span class="ruby-identifier">col</span>=<span class="ruby-identifier">col</span>.<span class="ruby-identifier">clone</span>
            <span class="ruby-identifier">col</span> = <span class="ruby-value str">&quot;&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">col</span><span class="ruby-operator">==</span><span class="ruby-keyword kw">nil</span>
            <span class="ruby-comment cmt"># td style and content</span>
            <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">old_html</span>
              <span class="ruby-identifier">hfile</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;&lt;td #{b} bgcolor=#{bg.to_s}&gt;#{font}&lt;font face=courier color=#{fg}&gt;#{col.gsub(/\ /,'&amp;nbsp;')}&lt;/font&gt;#{fontend}&lt;/td&gt;&quot;</span>
            <span class="ruby-keyword kw">else</span>
              <span class="ruby-identifier">hfile</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;&lt;td #{b} style=font-family:mono;background:#{bg.to_s};color:#{fg.to_s}&gt;#{font}#{col.gsub(/\ /,'&amp;nbsp;')}#{fontend}&lt;/td&gt;&quot;</span>
            <span class="ruby-keyword kw">end</span>
          }
          <span class="ruby-identifier">hfile</span>.<span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;&lt;/tr&gt;&quot;</span>
        }
        <span class="ruby-identifier">hfile</span>.<span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;&lt;body&gt;&lt;/table&gt;&lt;/html&gt;\n&quot;</span>
        <span class="ruby-identifier">hfile</span>.<span class="ruby-identifier">close</span>
      <span class="ruby-keyword kw">end</span>
    <span class="ruby-keyword kw">end</span></pre>
</body>
</html>